/*
 * @lc app=leetcode.cn id=2285 lang=golang
 *
 * [2285] 道路的最大总重要性
 */
package Solutions

import "sort"

// @lc code=start
func maximumImportance(n int, roads [][]int) int64 {
	cityRoads := make([]int, n)
	for _, v := range roads {
		cityRoads[v[0]]++
		cityRoads[v[1]]++
	}
	sort.Ints(cityRoads)
	ans := 0
	for i, v := range cityRoads {
		ans += (i + 1) * v
	}
	return int64(ans)
}

// @lc code=end
